import React from 'react';
import {Layout} from 'antd';
import './index.less';
import {connect} from "dva";
import Curd from "components/Curd";
import {getAllDeviceType} from "../../../../models/deviceType";
import BaseComponent from "components/Base/BaseComponent";
import Button from "antd/lib/button";

const {Content, Footer, Header} = Layout;

@connect(({bindDevice}) => ({bindDevice}))
export default class extends BaseComponent {

  componentDidMount() {
    this.init(this.props.patientId);
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    prevProps.patientId != this.props.patientId && this.init(this.props.patientId);
  }

  getNamespace() {
    return 'bindDevice';
  }

  getTableColumns() {
    return [
      {
        title: '设备ID',
        name: 'numeration',
        tableItem: {},
      },
      {
        title: '设备类型',
        name: 'deviceType',
        dict: getAllDeviceType(),
        tableItem: {},
      },
      {
        title: '状态',
        name: 'state',
        dict: [
          {code: 0, codeName: '离线'},
          {code: 1, codeName: '在线'},
        ],
        tableItem: {},
      },
    ];
  }

  init = () => {
    this.dispatch({
      type: `${this.getNamespace()}/init`,
      payload: {
        patientId: this.props.patientId,
        notice: this.showMsg
      },
    })
  }

  render() {

    console.log("render");

    const curdProps = {
      ...this.props,
      namespace: 'bindDevice',
      showToolbar: false,
      pagination: false,
      selectType: 'none',
      init: this.init,
      tableColumns: this.getTableColumns,
    }

    return (
      <div className="bind">
        <Curd {...curdProps}/>
        <div className="top">
          <Button onClick={this.init}>刷新</Button>
        </div>
      </div>
    );
  }

}
